package com.neusoft.elmboot.controller;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.VirtualWallet;
import com.neusoft.elmboot.po.VirtualWalletTransaction;
import com.neusoft.elmboot.service.VirtualWalletService;

@RestController
@RequestMapping("/VirtualWallet")
public class VirtualWalletController {
	@Autowired
	private VirtualWalletService virtualWalletService;

	//根据用户编号查询虚拟钱包
	@GetMapping("/{userId}")
	public VirtualWallet getVirtualWalletByUserId(@PathVariable String userId) throws Exception{
		return virtualWalletService.getVirtualWalletByUserId(userId);
	}
	
	//根据钱包编号查询余额
	@GetMapping("/inquireBalance/{walletId}")
	public BigDecimal getVirtualWalletBalanceByWalletId(@PathVariable Integer walletId) throws Exception{
		return virtualWalletService.getVirtualWalletBalanceByWalletId(walletId);
	}
	
	//根据钱包编号查询流水
	@GetMapping("/inquireTurnover/{walletId}")
	public List<VirtualWalletTransaction> getVirtualWalletTurnoverByWalletId(@PathVariable Integer walletId) throws Exception{
		return virtualWalletService.getVirtualWalletTurnoverByWalletId(walletId);
	}
	
	//根据钱包编号设置透支额度
	@PutMapping("/setOverdraftLimit/{walletId}/{overdraftLimit}")
	public int updateVirtualWalletOverdraftLimitByWalletId(@PathVariable Integer walletId, @PathVariable BigDecimal overdraftLimit) throws Exception{
		return virtualWalletService.updateVirtualWalletOverdraftLimitByWalletId(walletId, overdraftLimit);
	}
}